package com.joolun.cloud.mall.common.feign;

import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.joolun.cloud.common.core.constant.SecurityConstants;
import com.joolun.cloud.common.core.constant.ServiceNameConstants;
import com.joolun.cloud.common.core.util.R;
import com.joolun.cloud.weixin.common.dto.LoginDTO;
import com.joolun.cloud.weixin.common.dto.WxOpenDataDTO;
import com.joolun.cloud.weixin.common.entity.WxUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * @author
 */
@FeignClient(contextId = "feignWxUserService", value = ServiceNameConstants.WX_ADMIN_SERVICE)
public interface FeignWxUserService {

	/**
	 * 小程序获取登录后的微信用户
	 * @param loginDTO
	 * @param from
	 * @return
	 */
	@PostMapping("/wxuser/inside/ma/code2wxuser")
	R<WxUser> code2WxUserMa(@RequestBody LoginDTO loginDTO, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 公众号获取登录后的微信用户
	 * @param loginDTO
	 * @param from
	 * @return
	 */
	@PostMapping("/wxuser/inside/mp/code2wxuser")
	R<WxUser> code2WxUserMp(@RequestBody LoginDTO loginDTO, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 获取微信用户信息
	 * @param id
	 * @return
	 */
	@GetMapping("/wxuser/inside/{id}")
	R<WxUser> getById(@PathVariable("id") String id, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 通过appType+union_id查询微信用户
	 * @param unionId
	 * @param appType
	 * @return R
	 */
	@GetMapping("/wxuser/inside/by/unionid/{appType}/{unionId}")
	R<WxUser> getByUnionIdInside(@PathVariable("unionId") String unionId, @PathVariable("appType") String appType, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 通过小程序授权更新微信用户
	 * @param wxOpenDataDTO
	 * @param from
	 * @return
	 */
	@PutMapping("/wxuser/ma/inside")
	R<WxUser> updateByMaInside(@RequestBody WxOpenDataDTO wxOpenDataDTO, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 通过微信公众号网页授权更新用户信息
	 * @param wxOpenDataDTO
	 * @param from
	 * @return
	 */
	@PutMapping("/wxuser/mp/inside")
	R<WxUser> updateByMpInside(@RequestBody WxOpenDataDTO wxOpenDataDTO, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 新增或更新微信用户
	 * @param wxUser
	 * @param from
	 * @return
	 */
	@PostMapping("/wxuser/inside")
	R<WxUser> saveOrUpdate(@RequestBody WxUser wxUser, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 解密用户手机号信息
	 * @param wxOpenDataDTO
	 * @param from
	 * @return
	 */
	@PostMapping("/wxuser/ma/inside/phoneinfo")
	R<WxMaPhoneNumberInfo> getPhoneNoInfo(@RequestBody WxOpenDataDTO wxOpenDataDTO, @RequestHeader(SecurityConstants.FROM) String from);
}
